package com.walsai.pcsys.core.model;


import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

@Entity
public class Problem extends BaseObject implements Serializable{
	private static final long serialVersionUID = 123412341992L;
	
	public static final int PERMISSION_PUBLIC = 0;
	public static final int PERMISSION_PRIVATE = 1;
	
	private long id;

	private String name;
	private byte[] descriptionFile;
	private byte[] inputFile;
	private byte[] outputFile;
	private int permission;

	private Contest contest;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public long getId() {
		return id;
	}
	
	@Column(nullable=false)
	public String getName() {
		return name;
	}
	
	@Transient
	public byte[] getDescriptionFile() {
		return descriptionFile;
	}
	
	@Transient
	public byte[] getInputFile() {
		return inputFile;
	}
	
	@Transient
	public byte[] getOutputFile() {
		return outputFile;
	}
	
	@ManyToOne
	public Contest getContest() {
		return contest;
	}
	
	@Column(nullable=false)
	public int getPermission() {
		return permission;
	}
	
	
	
	public void setId(long id) {
		this.id = id;
	}
	public void setName(String name){
		this.name = name;
	}
	public void setDescriptionFile(byte[] descriptionFile) {
		this.descriptionFile = descriptionFile;
	}
	public void setInputFile(byte[] inputFile) {
		this.inputFile = inputFile;
	}
	public void setOutputFile(byte[] outputFile) {
		this.outputFile = outputFile;
	}
	public void setContest(Contest contest) {
		this.contest = contest;
	}	
	public void setPermission(int permission) {
		this.permission = permission;
	}

	@Override
	public boolean equals(Object o) {
        boolean result = false;
        if (o != null && getClass() == o.getClass()) {
            final Problem p = (Problem) o;
            if (this.id == p.id) {
                result = true;
            }
        }
        return result;
	}

	@Override
	public int hashCode() {
		return  (int)(this.id^(this.id>>>32));
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}
}
